package cn.tedu.api;

import java.util.Objects;

public class TestObject2 {
    public static void main(String[] args) {
        Cat c1 = new Cat();
        Cat c2 = new Cat();
        Cat c3 = new Cat("机器猫",300,10000.99,"大雄",'男');
        Cat c4 = new Cat("机器猫",300,10000.99,"大雄",'男');
        Dog d1 = new Dog();
        Dog d2 = new Dog();
        Dog d3 = new Dog("旺财",5,500);
        Dog d4 = new Dog("旺财",5,500);
        System.out.println(c1);
        System.out.println(d2.toString());
        System.out.println(d3);
        System.out.println(c3);
        System.out.println(c3.hashCode());
        System.out.println(c3 == c4);
        System.out.println(c3.equals(c4));
        //重写后equals()不用==比较，不比较地址值，而是比较类型、属性、属性值
        System.out.println(d3 == d4);//false  ==永远比较的是引用类型保存的地址值
        System.out.println(d3.equals(d4));//true 比较的是重写以后根据属性生成的哈希码值

    }



}
class Cat{
    String name;
    int age;
    double price;
    String host;
    char gender;

    public Cat() {
        System.out.println("小猫类无参构造");
    }

    public Cat(String name, int age, double price, String host, char gender) {
        this.name = name;
        this.age = age;
        this.price = price;
        this.host = host;
        this.gender = gender;
        System.out.println("小猫类含参构造");
    }
}
class Dog{
    String name;
    int age;
    double price;

    public Dog() {
        System.out.println("小狗类无参构造");
    }

    public Dog(String name, int age, double price) {
        this.name = name;
        this.age = age;
        this.price = price;
        System.out.println("小狗类全参构造");
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", price=" + price +
                '}';
    }


}